package com.cloud.cloudvideo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.cloudvideo.entity.ResultModel;
import com.cloud.cloudvideo.entity.SysUser;
import com.cloud.cloudvideo.service.UserService;


/**
 * 用户管理
 *
 */
@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService userService;
	
	
	@RequestMapping("/managerlist")
	public String managerlist() {
		return "manager/user/managerlist";
	}
	
	@RequestMapping("/tolist")
	public String normallist() {
		return "manager/user/normallist";
	}
	
	
	
	@RequestMapping("/toAdd")
	public String toAdd(Model model) {
		model.addAttribute("user", new SysUser());
		return "manager/user/add";
	}
	
	@RequestMapping("/toModify")
	public String toModify(Integer id,Model model) {
		SysUser user = userService.userInfo(id);
		model.addAttribute("user", user);
		return "manager/user/add";
	}
	
	
	@RequestMapping("/list")
	@ResponseBody
	public ResultModel<List<SysUser>> list(SysUser user,
			@RequestParam(value="page",required=false,defaultValue="1")Integer page){
		List<SysUser> list = userService.list(user,page);
		return ResultModel.successWithData(list, list.size());
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public ResultModel add(SysUser user){
		userService.add(user);
		return ResultModel.successWithNoData();
	}
	
	
	
	
}
